# -*- coding: UTF-8 -*-
import time
import conf
import requests
from utils import ip_utils
import send_initinfo
import log_helper
import json
import lte_controller

logger = log_helper.init_logging('heart')


def send_interval():
    while True:
        device_id = ip_utils.get_device_info()
        power_status = send_initinfo.get_device_power_status()
        status = lte_controller.get_lte_state()
        heart_params = {
            "cmd_type": "heart",
            "deviceId": device_id,
            "params": {
                "deviceStatus": status,
                "power_status": power_status
            }
        }
        headers = {"Content-Type": "application/json"}
        post_data = json.dumps(heart_params, ensure_ascii=False)
        logger.info("http_response:" + post_data)
        response = requests.post(conf.http_report_url, data=post_data, headers=headers)
        logger.info("response_data:" + response.text)
        time.sleep(5)
